/*
 * Copyright (c) 2009 LastFM.Desktop Anton Pavlik.
 * All Rights Reserved.
 * 
 * You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, 
 * with or without modifications, and in Source or Object form, provided that You meet the following 
 * conditions:
 * 1. You must give any other recipients of the Work or Derivative Works a copy of this License; and
 *
 * 2. You must cause any modified files to carry prominent notices stating that You changed the files; 
 * and
 *
 * 3. You must retain, in the Source form of any Derivative Works that You distribute, all copyright, 
 * patent, trademark, and attribution notices from the Source form of the Work, excluding those notices 
 * that do not pertain to any part of the Derivative Works.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); 
 * You may not use this file except in compliance with the License. 
 * You may obtain a copy of the License at 
 * 
 * http://www.apache.org/licenses/LICENSE-2.0 
 *
 * Unless required by applicable law or agreed to in writing, Licensor provides the Work 
 * (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 * CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties 
 * or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. 
 * YOU ARE SOLELY RESPONSIBLE FOR DETERMINING THE APPROPRIATENESS OF USING OR REDISTRIBUTING THE WORK
 * AND ASSUME ANY RISKS ASSOCIATED WITH YOUR EXERCISE OF PERMISSIONS UNDER THIS LICENSE. 
 */
package org.shake.lastfm.data;

import java.util.HashMap;
import java.util.Map;

public final class MP3Constants
{
    private static final Map<Long, Long> bitrate = new HashMap<Long, Long>();
    
    public static final int BIT0 = 0x01;
    public static final int BIT1 = 0x02;
    public static final int BIT2 = 0x04;
    public static final int BIT3 = 0x08;
    public static final int BIT4 = 0x10;
    public static final int BIT5 = 0x20;
    public static final int BIT6 = 0x40;
    public static final int BIT7 = 0x80;

    public static final int MASK_MP3_PADDING = BIT1;
    public static final int MASK_MP3_VERSION = BIT4 | BIT3;
    public static final int MASK_MP3_LAYER = BIT2 | BIT1;
    public static final int MASK_MP3_PROTECTION = BIT0;
    public static final int MASK_MP3_BITRATE = BIT7 | BIT6 | BIT5 | BIT4;
    public static final int MASK_MP3_ID = BIT3;
    public static final int MASK_MP3_FREQUENCY = BIT3 + BIT2;
    public static final int MASK_MP3_PRIVACY = BIT0;
    public static final int MASK_MP3_MODE = BIT7 | BIT6;
    public static final int MASK_MP3_MODE_EXTENSION = BIT5 | BIT4;
    public static final int MASK_MP3_COPY = BIT3;
    public static final int MASK_MP3_HOME = BIT2;
    public static final int MASK_MP3_EMPHASIS = BIT1 | BIT0;
    
    static
    {
        // MPEG-1, Layer I (E)
        bitrate.put(new Long(0x1E), new Long(32));
        bitrate.put(new Long(0x2E), new Long(64));
        bitrate.put(new Long(0x3E), new Long(96));
        bitrate.put(new Long(0x4E), new Long(128));
        bitrate.put(new Long(0x5E), new Long(160));
        bitrate.put(new Long(0x6E), new Long(192));
        bitrate.put(new Long(0x7E), new Long(224));
        bitrate.put(new Long(0x8E), new Long(256));
        bitrate.put(new Long(0x9E), new Long(288));
        bitrate.put(new Long(0xAE), new Long(320));
        bitrate.put(new Long(0xBE), new Long(352));
        bitrate.put(new Long(0xCE), new Long(384));
        bitrate.put(new Long(0xDE), new Long(416));
        bitrate.put(new Long(0xEE), new Long(448));

        // MPEG-1, Layer II (C)
        bitrate.put(new Long(0x1C), new Long(32));
        bitrate.put(new Long(0x2C), new Long(48));
        bitrate.put(new Long(0x3C), new Long(56));
        bitrate.put(new Long(0x4C), new Long(64));
        bitrate.put(new Long(0x5C), new Long(80));
        bitrate.put(new Long(0x6C), new Long(96));
        bitrate.put(new Long(0x7C), new Long(112));
        bitrate.put(new Long(0x8C), new Long(128));
        bitrate.put(new Long(0x9C), new Long(160));
        bitrate.put(new Long(0xAC), new Long(192));
        bitrate.put(new Long(0xBC), new Long(224));
        bitrate.put(new Long(0xCC), new Long(256));
        bitrate.put(new Long(0xDC), new Long(320));
        bitrate.put(new Long(0xEC), new Long(384));

        // MPEG-1, Layer III (A)
        bitrate.put(new Long(0x1A), new Long(32));
        bitrate.put(new Long(0x2A), new Long(40));
        bitrate.put(new Long(0x3A), new Long(48));
        bitrate.put(new Long(0x4A), new Long(56));
        bitrate.put(new Long(0x5A), new Long(64));
        bitrate.put(new Long(0x6A), new Long(80));
        bitrate.put(new Long(0x7A), new Long(96));
        bitrate.put(new Long(0x8A), new Long(112));
        bitrate.put(new Long(0x9A), new Long(128));
        bitrate.put(new Long(0xAA), new Long(160));
        bitrate.put(new Long(0xBA), new Long(192));
        bitrate.put(new Long(0xCA), new Long(224));
        bitrate.put(new Long(0xDA), new Long(256));
        bitrate.put(new Long(0xEA), new Long(320));

        // MPEG-2, Layer I (6)
        bitrate.put(new Long(0x16), new Long(32));
        bitrate.put(new Long(0x26), new Long(48));
        bitrate.put(new Long(0x36), new Long(56));
        bitrate.put(new Long(0x46), new Long(64));
        bitrate.put(new Long(0x56), new Long(80));
        bitrate.put(new Long(0x66), new Long(96));
        bitrate.put(new Long(0x76), new Long(112));
        bitrate.put(new Long(0x86), new Long(128));
        bitrate.put(new Long(0x96), new Long(144));
        bitrate.put(new Long(0xA6), new Long(160));
        bitrate.put(new Long(0xB6), new Long(176));
        bitrate.put(new Long(0xC6), new Long(192));
        bitrate.put(new Long(0xD6), new Long(224));
        bitrate.put(new Long(0xE6), new Long(256));

        // MPEG-2, Layer II (4)
        bitrate.put(new Long(0x14), new Long(8));
        bitrate.put(new Long(0x24), new Long(16));
        bitrate.put(new Long(0x34), new Long(24));
        bitrate.put(new Long(0x44), new Long(32));
        bitrate.put(new Long(0x54), new Long(40));
        bitrate.put(new Long(0x64), new Long(48));
        bitrate.put(new Long(0x74), new Long(56));
        bitrate.put(new Long(0x84), new Long(64));
        bitrate.put(new Long(0x94), new Long(80));
        bitrate.put(new Long(0xA4), new Long(96));
        bitrate.put(new Long(0xB4), new Long(112));
        bitrate.put(new Long(0xC4), new Long(128));
        bitrate.put(new Long(0xD4), new Long(144));
        bitrate.put(new Long(0xE4), new Long(160));

        // MPEG-2, Layer III (2)
        bitrate.put(new Long(0x12), new Long(8));
        bitrate.put(new Long(0x22), new Long(16));
        bitrate.put(new Long(0x32), new Long(24));
        bitrate.put(new Long(0x42), new Long(32));
        bitrate.put(new Long(0x52), new Long(40));
        bitrate.put(new Long(0x62), new Long(48));
        bitrate.put(new Long(0x72), new Long(56));
        bitrate.put(new Long(0x82), new Long(64));
        bitrate.put(new Long(0x92), new Long(80));
        bitrate.put(new Long(0xA2), new Long(96));
        bitrate.put(new Long(0xB2), new Long(112));
        bitrate.put(new Long(0xC2), new Long(128));
        bitrate.put(new Long(0xD2), new Long(144));
        bitrate.put(new Long(0xE2), new Long(160));
    }

    public static final Long getBitrate(Long key)
    {
        return bitrate.get(key);
    }
}